$(document).ready(function(){
    laydate.render({
      elem: '#startTime'
      ,type: 'datetime'
    });

    laydate.render({
      elem: '#endTime'
      ,type: 'datetime'
    });
    validateRule();
});

function removeLine(obj){
      layer.confirm('确定要删除选中的记录？', {
      		btn : [ '确定', '取消' ]
      	}, function(index) {
      	//alert($(obj).parents("tr").html());
      	   var trObj=$(obj).parents("tr");
      	   var trParent=$(trObj).parents("tbody");
            $(trObj).remove();
            var indexTr=1;
            var str="";

            $(trParent).children("tr").each(function(){
                $(this).children().first().html('SLA'+indexTr);
               indexTr++;
            });
            layer.close(index);
      	})
}

function number(){
    var count = $('#opp').val();
    var trObj ='';
    var serviceName=['服务响应','服务到场','服务解决','服务中断'];
    for(var i=0;i<parseInt(count);i++){
    trObj = trObj + '<tr><td class="center"><input type="hidden" name="slaDoList['+i+'].slaName" value="SLA'+(i+1)+'" type="display:block; margin-left:5px">SLA'+(i+1)+'</input></td>';
    for(var j=0;j<4;j++){
    if(j<3){
        trObj = trObj + '<td><input  name="slaDoList['+i+'].slaKpiDTOList['+j+'].kpiName" value="'+serviceName[j]+'"  class="hidden" type="text"/><input  name="slaDoList['+i+'].slaKpiDTOList['+j+'].kpiValue" class="slainput"  type="text"/></td>';
    }
      if(j == 3){
            trObj = trObj + '<td><input  name="slaDoList['+i+'].slaKpiDTOList['+j+'].kpiName" value="'+serviceName[j]+'"  class="hidden" type="text"/><input  name="slaDoList['+i+'].slaKpiDTOList['+j+'].kpiValue" class="slainput"   disabled="disabled" type="text"/></td>';
        }
       }
     trObj=trObj+'<td type="width:100%"><div type="text-align:center"><button type="button" class="btn1 btn  btn-primary" onclick="removeLine(this);"><i class="fa-plus hidden" aria-hidden="true"></i>删除</button></div></td></tr>';
    }
    $("#tab1 tbody").html('');
    $("#tab1 tbody").append(trObj);

}
function saveFirst() {
	$.ajax({
		cache : true,
		type : "POST",
		headers:PRIVATE_HEADERS,
		url : API_SERVER_URL + "smm/project/save",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.alert("保存成功，请进行下一步操作。");
				$("#auditID").val(data.id);
//				secondStepInit();
			} else {
				parent.layer.alert(data.msg)
			}

		}
	});
}
function validateRule() {
	$("#signupForm").validate({
		submitHandler:function(form){
            saveFirst();
        }
	})
}



